import common from '@/assets/js/mmk_common.js'
function pay (mallname, order_sn, price, sb_type) {
    //支付方法
    // let res = response.data;
    if (!wx.getStorageSync('open_id') || wx.getStorageSync('open_id') == '') {
        wx.showToast({
            title: '请先登录', //提示的内容,
            icon: 'none', //图标,
            duration: 2000, //延迟时间,
            mask: true, //显示透明蒙层，防止触摸穿透,
            success: res => { }
        })
        return false
    }
    common.fly_post(
        'api/v4_5/payment/wechatpay_miniapp_submit',
        {
            //预支付
            openid: wx.getStorageSync('open_id'),
            body: mallname,
            order_sn: order_sn,
            total: price,
            submit_type: sb_type
        },
        msg => {
            wx.hideLoading()
            let res = msg.data
            if (res.status_code == 0) {
                wx.requestPayment({
                    timeStamp: res.data.timeStamp,
                    nonceStr: res.data.nonceStr,
                    package: res.data.package,
                    signType: 'MD5',
                    paySign: res.data.paySign,
                    success: function (res) {
                       if (sb_type == 'market') {
                            wx.redirectTo({
                                url: '/ pages/ct_store/order_confirm/main'
                               
                            })
                        }
                    },
                    fail: function (res) {
                       
                    }
                })
            } else {
                wx.hideLoading()
                wx.showToast({
                    title: res.message,
                    icon: 'none',
                    duration: 2000,
                    mask: true
                })
                return false
            }
        }
    )
}

export default pay
